import 'package:hxdj/common/base_page/base_page.dart';
import 'package:hxdj/common/dio/dio_http.dart';
import 'package:hxdj/common/my_constant.dart';
import 'package:hxdj/message/message_page/message_viewmodel.dart';

class SysMessageViewModel extends BaseViewModel {
  //分页请求页数
  int pageNum = 0;

  List<SysMessageModel> dataList = [];

  //分页加载是否有数据, 默认有
  bool isHave = true;

  String messageId = "";
  SysMessageViewModel(msgId) {
    messageId = msgId;
  }
  //请求系统消息
  requestSysMessage({bool isFrist = false}) async {
    if (isFrist) {
      pageNum = 0;
      isHave = true;
      dataList.clear();
    }
    Map<String, dynamic> resultMap = await DioHttpManager().request(MyApi.getMemberNoticeList,
        method: DioHttpManager.post, data: {"page": pageNum, "limit": MyConstant.pageSize, "new_id": messageId});

    if (resultMap["code"] == 0) {
      List<dynamic> tempDataList = resultMap["data"];
      for (var element in tempDataList) {
        SysMessageModel sysMessageModel = SysMessageModel.fromMap(element);
        dataList.add(sysMessageModel);
      }
      if (tempDataList.length < MyConstant.pageSize) {
        isHave = false;
      }
    }
    pageNum += 1;

    notifyListeners();
  }
}
